package com.liuyk.mvp.p;

import android.content.Context;
import android.text.TextUtils;

import com.liuyk.entity.UserInfo;
import com.liuyk.mvp.v.m.LoginModel;
import com.liuyk.mvp.v.LoginView;

public class LoginPresenter extends BasePresenter implements LoginModel.LoginCallBack {
    private final LoginView mLoginView;
    private final LoginModel mLoginModel;

    public LoginPresenter(Context context, LoginView loginView) {
        super(context);
        mLoginView = loginView;
        mLoginModel = new LoginModel();
    }

    public void login(String userName, String password) {
        if (TextUtils.isEmpty(userName)) {
            mLoginView.userNameEmpty();
            return;
        }
        if (TextUtils.isEmpty(password)) {
            mLoginView.userPasswordEmpty();
            return;
        }
        mLoginModel.login(this);
    }

    @Override
    public void success(UserInfo userInfo) {
        mLoginView.login(userInfo);
    }

    @Override
    public void fail(String msg) {
        mLoginView.loginFail(msg);
    }
}
